<?php
include_once("bean/user.class.php");
include_once("bean/page.class.php");

/**
 * dashboard class. This is a class used to process all
 * logic of dashboard tab in admin page.
 */
class dashboard 
{
	var $db;
 	var $smarty;
 	
    function dashboard($db, $smarty)
	{
		//store pointer to db onject
		$this->db = $db;
		$this->smarty = $smarty;
	}
	
	/**
	 * This function will be call be index.php base on mod specified by GET param
	 */
	function process()
	{
		$num = 5;
		
		$pages = page::getLastestPage($this->db, $num);
		$this->smarty->assign_by_ref("PAGES", $pages);
		
		$users = user::getLastestUser($this->db, $num);
		$this->smarty->assign_by_ref("USERS", $users);
		
		$nPage = $this->db->get_var("select count(page_id) from " . TBL_PAGE);
		$nUser = $this->db->get_var("select count(ID) from " . TBL_USER);
		$nCats = $this->db->get_var("select count(cat_id) from " . TBL_CATEGORY);
		
		$Stats = sprintf(_("There are currently %s page(s) contained within %s category(s) and %s user(s)"),
					"<b style='color:blue'>" . $nPage . "</b>",
					"<b style='color:blue'>" . $nCats . "</b>",
					"<b style='color:blue'>" . $nUser . "</b>");
		$this->smarty->assign("STATS", $Stats);
		$this->smarty->display('dashboard.tpl');
	}
}
?>